home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Utilities
/
Random
/
Commodore 64c
/
SOURCE
/
AppleEvents.c
< prev
next >
Wrap
Text File
|
1994-03-19
|
5KB
|
212 lines
/*
Commodore 64 Emulator v0.2 Earle F. Philhower III
Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <AppleEvents.h>
#include <Balloons.h>
#include "ProcessorTypes.h"
#include "Error.h"
#include "FileTypes.h"
/* AEVT Routines */
OSErr DoQUIT();
pascal OSErr AEHandleQUIT(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
OSErr DoOAPP();
pascal OSErr AEHandleOAPP(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
OSErr DoODOC(const AppleEvent *theAE,const AppleEvent *theRp);
pascal OSErr AEHandleODOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
OSErr DoPDOC(const AppleEvent *theAE,const AppleEvent *theRp);
pascal OSErr AEHandlePDOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
byte InstallAppleEventHandlers();
DescType missedTypeCode;
long missedActualSize;
#define InstallFinder(z,y) AEInstallEventHandler(kCoreEventClass, z, y, 0, false)
#define InstallCore(z,y) AEInstallEventHandler(kAECoreSuite, z, y, 0, false)
#define MissedParams(z) \
(AESizeOfAttribute(z, keyMissedKeywordAttr, \
&missedTypeCode, &missedActualSize) != errAEDescNotFound)
OSErr DoQUIT()
{
CleanUpCommodore();
ExitToShell();
}
pascal OSErr AEHandleQUIT(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
DescType typeCode;
long actualSize;
err = DoQUIT();
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
/* There should be NO parameters sent to us..if there are, someone's
got a REAL problem! (not us, though!) */
return(err);
}
OSErr DoOAPP()
{
}
pascal OSErr AEHandleOAPP(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
DescType typeCode;
long actualSize;
err = DoOAPP();
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
return(err);
}
void OpenFSSpec(FSSpec *spec)
{
FInfo finfo;
FSpGetFInfo(spec, &finfo);
switch(finfo.fdType)
{
case DISKFTYPE:
AttachFloppyImage(spec);
break;
case RAMFTYPE:
LoadRAMFS(spec);
break;
case PRINTERFTYPE:
break;
case TAPEFTYPE:
LoadTapeFS(spec);
break;
}
}
OSErr DoODOC(theAppleEvent, theReply)
const AppleEvent *theAppleEvent, *theReply;
{
OSErr err;
FSSpec myFSS;
AEDescList *docList;
long items;
long index;
AEKeyword keywd;
DescType typeCode;
Size actualSize;
err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
if (err!=noErr) return (err);
err = AECountItems(docList, &items);
if (err!=noErr) return (err);
for (index=1; index<=items; index++) {
err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode, (Ptr)&myFSS,
sizeof(myFSS), &actualSize );
if (err!=noErr) {AEDisposeDesc(docList); return (err);}
OpenFSSpec(&myFSS);
/* p2cstr(myFSS.name);*/
/* printf("ODOC %s\n", myFSS.name);*/}
err = AEDisposeDesc(docList);
return(err);
}
pascal OSErr AEHandleODOC(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
DescType typeCode;
long actualSize;
err = DoODOC(theAppleEvent, theReply);
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
return(err);
}
OSErr DoPDOC(theAppleEvent, theReply)
const AppleEvent *theAppleEvent, *theReply;
{
OSErr err;
FSSpec myFSS;
AEDescList *docList;
long items;
long index;
AEKeyword keywd;
DescType typeCode;
Size actualSize;
err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
if (err!=noErr) return (err);
err = AECountItems(docList, &items);
if (err!=noErr) return (err);
for (index=1; index<=items; index++) {
err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode, (Ptr)&myFSS,
sizeof(myFSS), &actualSize );
if (err!=noErr) {AEDisposeDesc(docList); return (err);}
/* p2cstr(myFSS.name);*/
/*printf("PDOC %s\n", myFSS.name)*/;}
err = AEDisposeDesc(docList);
return(err);
}
pascal OSErr AEHandlePDOC(theAppleEvent, theReply, theRefCon)
const AppleEvent *theAppleEvent, *theReply;
long theRefCon;
{
OSErr err=noErr;
DescType typeCode;
long actualSize;
err = DoPDOC(theAppleEvent, theReply);
if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
return(err);
}
byte InstallAppleEventHandlers()
{
short err;
if ((err=InstallFinder(kAEQuitApplication, AEHandleQUIT))!=0) return -1;
if ((err=InstallFinder(kAEOpenApplication, AEHandleOAPP))!=0) return -1;
if ((err=InstallFinder(kAEOpenDocuments, AEHandleODOC))!=0) return -1;
if ((err=InstallFinder(kAEPrintDocuments, AEHandlePDOC))!=0) return -1;
return kNoError;
}